{__NOLAYOUT__}
<div class="prompt-pop" data-type="detail_add" id="<?php echo $funcid ?>" style="z-index: {$zindex}" funcid="{$funcid}" >
  <div class="title">
    <span class="pop-name">选择商品</span>
    <a href="javascript:void(0);" onclick="$(this).parents('.prompt-pop').remove();_asr.closePopup('{$funcid}');" class="close iconfont">&#xe60d;</a>
   </div>
  <div class="trees-box">
    <div> <!-- class="trees-info" -->
      <div class="screening treesorder">
      <form id="<?php echo $funcid; ?>-selectProduct-Search" action="{:U('/Home/Popup/index?func=SelectProduct&ordertype='.$ordertype)}" method="get">
        <input type="hidden" name="funcid" value="{$funcid}" />
          <input type="hidden" name="zindex" value="{$zindex}" />
          <input type="hidden" name="pfuncid" value="<?php echo $pfuncid; ?>" />
          <input type="hidden" name="id" value="<?php echo $orderid; ?>" />
          <input type="hidden" name="category_code" value="{$search['category_code']}">
          <input type="hidden" name="selecttype" value="<?php echo $selecttype; ?>" />
        <ul class="form form-style1">
            <li> <span class="tit">商品编码</span>
                <div class="item">
                    <div class="txt-box">
                        <input type="text" name="goods_no" value="{$search['goods_no']}" class="txt">
                    </div>
                </div>
            </li>
            <li> <span class="tit">商品条码</span>
                <div class="item">
                    <div class="txt-box">
                        <input type="text" name="barcode" value="{$search['barcode']}" class="txt">
                    </div>
                </div>
            </li>
            <li><span class="tit">商品名称</span>
                <div class="item">
                    <div class="txt-box">
                        <input type="text" name="name" value="{$search['name']}" class="txt">
                    </div>
                </div>
            </li>
            <li><span class="tit">商品分类</span>
                <div class="item">
                    <div class="txt-box">
                        <input type="text" name="category_code_name" value="{$search['category_code_name']}" class="txt">
                        <button type="button" class="txt-search" onclick="return _asr.popup('Category','<?php echo "$funcid"; ?>','<?php echo "$funcid"; ?>-StockAdjust-selectProduct-Search','Single','category_code','category_code_name'); "><i class="iconfont">&#xe60e;</i></button>
                        <button type="submit" class="txt-clear" onclick="_asr.setvaluebyname('<?php echo "$funcid"; ?>-StockAdjust-selectProduct-Search','category_code','');_asr.setvaluebyname('<?php echo "$funcid"; ?>-StockAdjust-selectProduct-Search','category_code_name','');return false;" <?php if($search['category_code_name']===""): ?> style="display:none"<?php endif; ?> ><i class="iconfont">&#xe616;</i></button>
                    </div>
                </div>
            </li>
            <if condition="(!in_array($ordertype,array('stockadjust','stockin','stockout')))">
            <li><span class="tit">仓库</span>
                <div class="item">
                  <div class="txt-box">
                    <input type="hidden" name="storage_code" value="{$search['storage_code']}" />
                    <input  type="text" class="txt" name="storage_code_name" readonly="readonly" value="<?php echo $search['storage_code_name']; ?>">
                    <button type="button" class="txt-search" onclick="return _asr.popup('Storage','<?php echo "$funcid"; ?>','<?php echo "$funcid"; ?>','Single','storage_code','storage_code_name'); "><i class="iconfont">&#xe60e;</i></button>
                  </div>
                </div>
            </li>
            <else />
            <input type="hidden" name="storage_code" value="{$search['storage_code']}" />
            </if>
        </ul>
        <!--筛选表单-->
        <div class="tress-sub abe-txtc">
          <input type="submit" value="搜索" class="btn btn-org btn-sm mrg_10" onclick="return _asr.submit('<?php echo $funcid;?>', this, '')">
          <input type="button" value="清除"  class="btn btn-blue btn-sm mrg_10" onclick="return <?php echo $funcid; ?>_clearsearch('<?php echo $funcid; ?>-selectProduct-Search');">
        </div>
        </form>
      </div>
      <div class="table-box">
        <div class="table-in" style="height: 300px;">
        <form action="{:U('Home/StockAdjust/index?func=saveSelectProduct')}" method="post" id="<?php echo $funcid;?>-Select-Product-Form">
          <input type="hidden" name="orderid" value="{$orderid}" />
          <input type="hidden" name="funcid" value="{$funcid}" />
          <input type="hidden" name="pfuncid" value="{$pfuncid}" />
          <input type="hidden" name="p" value="{$p}" />
          <input type="hidden" name="zindex" value="{$zindex}" />
          <input type="hidden" name="storage_code" value="{$search['storage_code']}" />
          <table border="0" cellspacing="0" cellpadding="0" class="pub-table">
            <colgroup>
            <col style="width:40px;">
            <col style="width:80px;">
            <col style="width:80px;">
            <col style="width:80px;">
            <col style="width:100px;">
            <col style="width:100px;">
            <col style="width:80px;">
            <col style="width:80px;">
            <col style="width:80px;">
            <if condition="(in_array($ordertype,array('stockout')))">
            <col style="width:80px;">
            <col style="width:80px;">
            </if>
            <if condition="(in_array($ordertype,array('stockin')))">
            <col style="width:80px;">
            </if>
            <col style="width:100px;">
            <col style="width:100px;">
            <if condition="(in_array($ordertype,array('stockadjust','stockin','stockout')))">
            <col style="width:80px;">
            </if>
            </colgroup>
            <tbody>
              <tr>
                <th>
                  <if condition="strtolower($selecttype) eq 'multi'">
                  <input type="checkbox" onclick="return _asr.selectAll(this);">
                  </if>
                </th>
                <th class="abe-txtl">商品编码</th>
                <th class="abe-txtl">商品名称</th>
                <th class="abe-txtl">商品条码</th>
                <th class="abe-txtl">商品分类</th>
                <th class="abe-txtl">规格信息</th>
                <th>品牌</th>
                <th>税率</th>
                <th>单价</th>
             <if condition="(in_array($ordertype,array('stockout')))">
                <th>库存</th>
                <th>订单数量</th>
             </if>
             <if condition="(in_array($ordertype,array('stockin')))">
                <th>未入库数量</th>
             </if>
                <th>数量</th>
                <th>单价</th>
             <if condition="(in_array($ordertype,array('stockadjust','stockin','stockout')))">
                <th>库位</th>
             <else>   
                <th></th>
             </if>
              </tr>
              <?php $old_goods_no=""; ?>
              <volist name="list"  id="item" mod="2">              
                <tr class="<eq name="mod" value="1">even<else/>odd</eq>">
                  <td><input j='<?php echo json_encode($item); ?>' type="<if condition="strtolower($selecttype) eq 'multi'">checkbox<else />radio</if>" data-type="select" name="id[]"  value="{$item["id"]}" /></td>
                  <!-- <if condition="$item['detail_qty'] gt 0" > checked </if>  -->
                  <td class="abe-txtl"><a href="<?php echo U("/Home/Goods/index?func=view&no=$item[goods_no]") ?>','<?php echo filterFuncId("/Home/Goods_view","no=$item[goods_no]");?>"  target="_blank" class="vi-blue"  >{$item["goods_no"]}</a></td>
                  <td class="abe-txtl"><div class="newline">{$item["name"]}</div></td>
                  <td class="abe-txtl">{$item["barcode"]}</td >
                  <td class="abe-txtl">{$item['category_code']|get_table_Category="name"}</td>
                  <td class="abe-txtl">{$item["style_info"]}</td>
                  <td>{$item['brand_code']|get_table_Brand="name"}</td>
                  <td>{:system_format("F32",100*$item['tax_rate'],1)}</td>
                  
                  <if condition="(in_array($ordertype,array('Purchase')))">
                  <td>{$item["purchase_price"]}<input type="hidden" class="pbtxt" name="price_{$item['id']}" value="{$item['purchase_price']}" /></td>                  
                  <else />
                  <td>{$item["detail_price"]}<input type="hidden" class="pbtxt" name="price_{$item['id']}" value="{$item['detail_price']}" /></td>
                  </if>
               <if condition="(in_array($ordertype,array('stockout')))">
                  <td><span class="vi-org">{$item['cur_qty']}</span></td>
                  <td>
                     <if condition="($old_goods_no neq $item['goods_no'])">
                     <span class="vi-org">{$item['detail_qty']}</span>
                     </if>        
                  </td>
                  <if condition="($item['cur_qty'] lt $item['detail_qty'])">
                  <?php $item['detail_qty']=$item['cur_qty']; ?>
                  </if>
               </if>
               <if condition="(in_array($ordertype,array('stockin')))">
                  <td><span class="vi-org">{$item['detail_qty']}</span><input type="hidden" name="order_qty_{$item['id']}" value="{$item['detail_qty']}"></td>
               </if>          
                  <td>
                        <div class="pro-num"><input type="text" class="pbtxt" name="qty_{$item['id']}" value="{$item['detail_qty']}" onblur="<?php echo $funcid ?>_check_select(this);"></div>
                  </td>
                  <td>
                      <div class="pro-num"><input type="text" class="pbtxt" value="{$item['detail_price']}" name="price_{$item['id']}" onblur="<?php echo $funcid ?>_check_select(this);"></div>
                  </td>
                  <td>
                        <if condition="(in_array($ordertype,array('stockadjust','stockin')))">
                         <div class="newtxtbox">
                           <input type="hidden" name="storage_location_{$item['id']}" value="" />
                           <input type="hidden" name="goods_id_{$item['id']}" value="{$item['id']}" />
                           <input  type="text" class="pbtxt txt0" name="storage_location_{$item['id']}_name" readonly="readonly" value="" style="width:140px;">
                         <button type="submit" class="txt-search" onclick="return _asr.popup('StorageLocation','<?php echo $funcid; ?>','<?php echo $funcid; ?>-Select-Product-Form','Single','storage_location_{$item[id]}','storage_location_{$item[id]}_name'); " relation="storage_code|goods_id_{$item['id']}"><i class="iconfont" relation="storage_code|goods_id_{$item['id']}">&#xe60e;</i></button>
                         <button type="submit" class="txt-clear" onclick="_asr.setvaluebyname('<?php echo $funcid;?>-Select-Product-Form','storage_location_{$item['id']}','');_asr.setvaluebyname('<?php echo $funcid;?>-Select-Product-Form','storage_location_{$item['id']}_name','');return false;" style="display:none;" ><i class="iconfont">&#xe616;</i></button>
                       </div>
                       <else />
                       <div class="pro-num">
                       {$item["location_code"]}
                       <input type="hidden" name="storage_location_{$item['id']}" value="{$item["location_code"]}" />
                       </div>
                       </if>
                    </td>
                </tr> 
                <?php $old_goods_no=$item['goods_no']; ?>
              </volist>  
            </tbody>
          </table>
          </form>
        </div>
          <div class="blank15"></div>
          <?php echo $page; ?>
          <div class="blank15"></div>
      </div>
    </div>
  </div>
  <div class="pop-sub abe-txtc">
    <input type="submit" value="保存" class="btn btn-org mrg_10" onclick="return <?php echo $funcid ?>_submit(0);">
    <input type="submit" value="保存并继续" class="btn btn-org mrg_10" onclick="return <?php echo $funcid ?>_submit(1);">
    <input type="submit" value="取消" class="btn" onclick="$(this).parents('.prompt-pop').remove();_asr.closePopup('{$funcid}');">
  </div>
</div>
<script>
  function <?php echo $funcid ?>_init() {
    var _this = $("#<?php echo $funcid ?>");
    var ppw = _this.width()/2;
    _this.css({'margin-left':-ppw});
  }
   function <?php echo $funcid; ?>_clearsearch(_frm){
         _asr.setvaluebyname(_frm,"goods_no", "" );
         _asr.setvaluebyname(_frm,"barcode", "" );
         _asr.setvaluebyname(_frm,"category_code", "" );
         _asr.setvaluebyname(_frm,"category_code_name", "" );
         _asr.setvaluebyname(_frm,"storage_code", "" );
         _asr.setvaluebyname(_frm,"storage_code_name", "" );
        // _asr.clearCheck("{$funcid}_storage_code");     
   }
  function <?php echo $funcid ?>_refresh() {
    _asr.submit('<?php echo $funcid;?>', $("#<?php echo $funcid ?>").find("form").eq(1), '');
  }
  
  function <?php echo $funcid ?>_submit(close) {
    var _id = '<?php echo $funcid;?>-Select-Product-Form';
    <?php if(strtolower($selecttype) == 'multi'): ?>
    var _m = $("#"+_id).find("input[type=checkbox][data-type=select]:checked");
    <?php else: ?>
    var _m = $("#"+_id).find("input[type=radio][data-type=select]:checked");
    <?php endif; ?>
    
    if(_m.size() == 0) {
      alert("至少选择一条数据");
      return false;
    }
    if(close == 1) {
      return _asr.submit('<?php echo $funcid;?>', '<?php echo $funcid;?>-Select-Product-Form', '{:U($submit_url)}');
    } else {
      return _asr.submit('<?php echo $funcid;?>', '<?php echo $funcid;?>-Select-Product-Form', '{:U("$submit_url&close=1")}');
    }
  }
  
  function <?php echo $funcid ?>_check_select(o) {
    <?php if(strtolower($selecttype) == 'multi'): ?>
    var _m = $(o).parents("tr").find("input[type=checkbox][data-type=select]");
    <?php else: ?>
    var _m = $(o).parents("tr").find("input[type=radio][data-type=select]");
    <?php endif; ?>
    if($(o).val() != "") {
      _m.prop("checked", true);
    }
  }
</script>